<?php

namespace app\admin\controller;

use think\Log;

class Vipintro extends Admin
{
    public function __construct()
    {
        parent::__construct();
        $this->model = "VipIntro";
        $this->modelDb = model("VipIntro");
        $this->assign("model", $this->model);
    }

    public function index()
    {
        return $this->fetch();
    }

    public function get_where_map()
    {
        $whereDatas = [];
        return $whereDatas;
    }

    // 打开添加消息的界面
    public function add()
    {
        $info = model('VipIntro')->find();
        if ($info) {
            $this->assign("info", $info);
        } else {
            $info['id'] = "";
            $info['content'] = "";
            $this->assign("info", $info);
        }
        return $this->fetch();
    }

    // 保存新添加的消息
    public function save_intro()
    {
        $id = input('post.id');
        $content = input('post.content');
        if (!$content) {
            return json(['status' => 0, 'msg' => '请输入介绍内容']);
        }
        if (!$id) {
            $data = [
                'content' => $content,
                'datetime' => time()
            ];
            $this->modelDb->save_data($data);
            return json(['status' => 1, 'msg' => '操作成功']);
        } else {
            $count = $this->modelDb->where('id', $id)->count();
            if ($count) {
                $this->modelDb->where('id', $id)->update(['content' => $content, 'datetime' => time()]);
                return json(['status' => 1, 'msg' => '操作成功']);
            } else {
                return json(['status' => 0, 'msg' => '操作失败，请重试']);
            }
        }
    }
}